package hzn.controller;

import hzn.entity.Dept;
import hzn.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

@RestController
public class DeptController_Provider {
    @Value("${server.port}")
    String port;
    int num;
    @Autowired
    DeptService service;

    @RequestMapping("/dept/zk")
    public String deptZk(){
        return "zookeeper:"+port+ "--"+UUID.randomUUID();
    }

    @PostMapping("/dept/add")
    //必须给参数添加RequestBody注解，用于从http请求体中提取数据
    public boolean add(@RequestBody Dept dept){
        return service.add(dept);
    }

    @GetMapping("/dept/get/{id}")
    public Dept get(@PathVariable Integer id){
        System.out.println("provider01--num:=====***"+num++);
        return service.get(id);
    }

    @GetMapping("/dept/list")
    public List<Dept> getAll(){
        System.out.println(Thread.currentThread().getName());
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {}
        System.out.println("provider01--num:"+num++);
        return service.list();
    }
}
